import java.util.Scanner;

/**
 * @author vivi
 * @description
 * @date 2024/5/25
 */
public class demo1 {
    public static void main (String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNext())
        {
            int n = in.nextInt();
            int ret = 1;
            while(ret - 1 <= n) {
                ret *= 2;
            }
            System.out.println(ret / 2 - 1);
        }

    }
}
